package net.vinote.sosa.web.context;

import java.io.IOException;

import org.springframework.core.io.Resource;
import org.springframework.web.context.support.XmlWebApplicationContext;

import net.vinote.sosa.context.support.SosaResource;

public class SosaXmlWebApplicationContext extends XmlWebApplicationContext {
	private SosaResource sosaResource = new SosaResource(this);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.context.support.AbstractApplicationContext#getResources
	 * (java.lang.String)
	 */
	@Override
	public Resource[] getResources(String locationPattern) throws IOException {
		if (!sosaResource.isInit()) {
			sosaResource.init(super.getResource("classpath:sosa-conf.properties"));
		}
		return sosaResource.getResources(locationPattern, super.getResources(locationPattern));
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.springframework.core.io.DefaultResourceLoader#getResource(java.lang
	 * .String)
	 */
	@Override
	public Resource getResource(String location) {
		return sosaResource.getProxyResource(super.getResource(location));
	}
}
